package com.lexiang.base.controller;

import com.lexiang.base.pojo.Label;
import com.lexiang.base.service.LabelService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.lang.reflect.Method;
import java.util.List;

/**
 * @BelongsProject:lx_parent
 * @BelongsPackage:com.lexiang.base.controller
 * @Author:linchong
 * @CreateTime:2019-04-02 19:45
 * @Description:标签控制器层
 */
@RestController
@CrossOrigin  //跨域
@RequestMapping("/label")
public class LabelController {

    @Autowired
    private LabelService labelService;

    @RequestMapping(method = RequestMethod.GET)
    public Result findAll(){
        return new Result(true, StatusCode.OK,"查询全部数据成功",labelService.findAll());
    }

    @RequestMapping(value = "/{labelId}",method = RequestMethod.GET)
    public Result findById(@PathVariable("labelId") String labelId){
        return  new Result(true,StatusCode.OK,"查询指定ID数据成功",
                labelService.findById(labelId));
    }

    @RequestMapping(method = RequestMethod.POST)
    public Result add(@RequestBody Label label){
        labelService.add(label);
        return new Result(true,StatusCode.OK,"新增数据成功");
    }

    @RequestMapping(method = RequestMethod.PUT)
    public Result update(@RequestBody Label label,@PathVariable String id){
        label.setId(id);
        labelService.update(label);
        return new Result(true,StatusCode.OK,"修改数据成功");
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public Result deleteById(@PathVariable String id){
        labelService.deleteById(id);
        return new Result(true,StatusCode.OK,"删除数据成功");
    }


}
